#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <vector>
using namespace std;

int cnt[5], m, ret;
int hashi[13] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };

void dfs(int n)
{
    if (n > 12)
    {
        ret++;
        return;
    }
    if (hashi[n] >= 0) dfs(n + 1);
    else
    {
        for (int k = 1; k <= 4; k++)
        {
            if (cnt[k] < abs(hashi[n])) continue;
            cnt[k] -= abs(hashi[n]);
            dfs(n + 1);
            cnt[k] += abs(hashi[n]);
        }
    }
}

int main()
{
    for (int i = 1; i <= 4; i++) cin >> cnt[i];
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int first, second, firsthead, secondhead;
        cin >> first >> second;
        firsthead = first, secondhead = second;
        while (hashi[firsthead] >= 0) firsthead = hashi[firsthead];
        while (hashi[secondhead] >= 0) secondhead = hashi[secondhead];
        if (firsthead == secondhead) continue;
        if (firsthead > secondhead)
        {
            int tmp = firsthead;
            firsthead = secondhead, secondhead = tmp;
        }
        hashi[firsthead] += hashi[secondhead];
        hashi[secondhead] = firsthead;
    }
    dfs(1);
    cout << ret;
    return 0;
}